﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Xml.Linq;

namespace XLDL
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            Application["HomNay"] = 0;
 	        Application["HomQua"] = 0;
 	        Application["TuanNay"] = 0;
 	        Application["TuanTruoc"] = 0;
 	        Application["ThangNay"] = 0;
 	        Application["ThangTruoc"] =0;
 	        Application["TatCa"] = 0;
 	        Application["visitors_online"] = 0;
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            XL_Gio_hang gio_hang = new XL_Gio_hang();
            Session["gio_hang"] = gio_hang;
            XL_DS_DaXem his = new XL_DS_DaXem();
            Session["his"] = his;
            Session["ten_dang_nhap"] = "";
            Session["slg"] = "";
            Session["size"] = "";
            Session["id"] = "";
            Session["tk"] = "";
            Session["ky"] = "";
            Session["user"] = "";
            Session["gt"] = "";
            Session["ok"] = "";
            Session["yes"] = "";
            Session["tooltip"] =0;
            Session["sx"] ="";
            Session["KeySort"] = "";
         //   Session.Timeout = 150;
 	        Application.Lock();
 	        Application["visitors_online"] = Convert.ToInt32(Application["visitors_online"]) + 1;
 	        Application.UnLock();
 	        try
 	        {
 	            XLDL  mThongKe = new XLDL();
 	            DataTable dtb = mThongKe.TableThongKe();
 	            if (dtb.Rows.Count > 0)
 	            {
 	                Application["HomNay"] = long.Parse("0" + dtb.Rows[0]["HomNay"]).ToString("#,###");
 	                Application["HomQua"] = long.Parse("0" + dtb.Rows[0]["HomQua"]).ToString("#,###");
 	                Application["TuanNay"] = long.Parse("0" + dtb.Rows[0]["TuanNay"]).ToString("#,###");
 	                Application["TuanTruoc"] = long.Parse("0" + dtb.Rows[0]["TuanTruoc"]).ToString("#,###");
 	                Application["ThangNay"] = long.Parse("0" + dtb.Rows[0]["ThangNay"]).ToString("#,###");
 	                Application["ThangTruoc"] = long.Parse("0" + dtb.Rows[0]["ThangTruoc"]).ToString("#,###");
 	                Application["TatCa"] = long.Parse("0" + dtb.Rows[0]["TatCa"]).ToString("#,###");
 	            }
 	            dtb.Dispose();
 	            mThongKe = null;
 	        }
 	        catch { }
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            Application.Lock();
 	        Application["visitors_online"] = Convert.ToUInt32(Application["visitors_online"]) - 1;
 	        Application.UnLock();
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}